/*
 * @lc app=leetcode.cn id=202 lang=rust
 *
 * [202] 快乐数
 */

// @lc code=start
impl Solution {
    pub fn is_happy(n: i32) -> bool {
        if(n <= 0) 
        {return false;}
        use std::collections::HashSet;
        let mut set = HashSet::new();

        let mut m = n;

        while(!set.contains(&m))
        {
            if(m == 1) {return true;}
            // if(m <= 9) {return false;}
            set.insert(m);
            let mut tmp = 0;
            while(m != 0)
            {
                let t = m / 10;
                let yushu = m - t * 10;
                tmp += yushu * yushu;
                m = t;
            }
            m = tmp;
        }
        return false;
    }

}
// @lc code=end

